package com.jinlejia.erp.ui.common;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jinlejia.erp.R;

/**
 * @author SongJiaTai
 * @description:
 * @date :2020/7/20 11:38
 */
public class DoubleCommonDialog extends AlertDialog {
    private String title,content;
    private Boolean cancel = true;

    protected DoubleCommonDialog(Context context,String title,Boolean cancel) {
        super(context);
        this.title = title;
        this.cancel = cancel;
}

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = this.getWindow();
        // *** 主要就是在这里实现这种效果的.
        // 设置窗口的内容页面,shrew_exit_dialog.xml文件中定义view内容
        this.setCanceledOnTouchOutside(false);
        window.setContentView(R.layout.dialog_common_double);
        window.setGravity(Gravity.CENTER);
        window.setBackgroundDrawable(new ColorDrawable());
        window.setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        //Title
        TextView titleTxt = (TextView) window.findViewById(R.id.title);
        titleTxt.setText(title);
        //取消
        TextView cancleTxt = (TextView) window.findViewById(R.id.id_cancel);
        if (cancel){
            cancleTxt.setVisibility(View.VISIBLE);
        }else{
            cancleTxt.setVisibility(View.GONE);
        }
        cancleTxt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        //确定
        TextView confirmTxt = (TextView) window.findViewById(R.id.id_confirm);
        confirmTxt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if( null != confirmListener )
                confirmListener.confirm();
            }
        });
    }

    public interface OnConfirmListener {
        void confirm();
    }

    private OnConfirmListener confirmListener;

    public void setConfirmListener(OnConfirmListener listener) {
        this.confirmListener = listener;
    }

}
